package com.example.controller;

import com.example.pojo.User;
import io.swagger.annotations.*;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

@RestController
@Api(tags = "测试1")
@RequestMapping("/hello")
public class HelloController {

    @ApiOperation(value = "你好")
    @PostMapping("/hello")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", name = "id", value = "账号", required = true, dataType = "String"),
            @ApiImplicitParam(paramType = "query", name = "name", value = "姓名", required = true, dataType = "String"),
            @ApiImplicitParam(paramType = "query", name = "age", value = "年龄", required = false, dataType = "Integer"),
    })
    public Map<String, Object> hello(String id, String name, Integer age) {
        HashMap<String, Object> hm = new HashMap<>();
        hm.put("账号", id);
        hm.put("姓名", name);
        hm.put("年龄", age);
        return hm;
    }

    @ApiOperation(value = "不好")
    @PostMapping("/nohello")
    @ApiImplicitParam(paramType = "body", name = "user", value = "用户", required = true, dataType = "User")
    public ResponseEntity<String> nohello(User user){
        if (user.getId() == null){
            return new ResponseEntity<>("id不可为空", HttpStatus.BAD_REQUEST);
        }
        return new ResponseEntity<>("用户验证成功", HttpStatus.OK);
    }
}